import request from '@/utils/request'
import { CommonSearch } from '@/config/list'
import { StarTreeNode } from '@/model/common/tree/model'
import { MenuList, MenuBeanData } from '@/model/system/menu/model'

export function loadAllMenu () {
  return request<StarTreeNode[]>({
    url: '/starMenu/loadAllMenu',
    method: 'get'
  })
}

export function loadMenuByFid (data: CommonSearch) {
  return request<MenuList>({
    url: '/starMenu/loadMenuByFid',
    data: data,
    method: 'post'
  })
}

export function loadMenuById (id: string) {
  return request<MenuBeanData>({
    url: `/starMenu/loadMenuById?id=${id}`,
    method: 'get'
  })
}

export function deleteMenu (id: string) {
  return request({
    url: `/starMenu/removeMenu?id=${id}`,
    method: 'post'
  })
}

export function saveMenu (formData: MenuBeanData) {
  return request({
    url: '/starMenu/saveMenu',
    data: formData,
    method: 'post'
  })
}

export function getMaxIndex (fid: string) {
  return request<string>({
    url: `/starMenu/getMaxIndex?fid=${fid}`
  })
}
